﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Model;

namespace DAL
{
    public class StudentDAL
    {
        DbContext db = new MyDbContext();
    
        public IQueryable<Student> Getllist(Expression<Func<Grade, bool>> where)
        {
            //Include是包括那张表
            //set是设置哪个表？
            return db.Set<Student>().AsNoTracking().Include("Grade").Select(o => o);
        }

        public bool Add(Student stu) 
        {
            db.Set<Student>().Add(stu);
            return db.SaveChanges() > 0;
        }

        public bool Delete(Expression<Func<Student, bool>> where) 
        {
            var entity = db.Set<Student>().Where(where);
            foreach (var item in entity)
            {
                db.Set<Student>().Remove(item);
            }
             return db.SaveChanges() > 0;
        }
    }
}
